import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

/**
 * 接口字段权限维护 /ciam/sub-account-org/api/:usedId
 * DataTable
 * @date 2019-07-11
 */
import React, { Component } from 'react';
import { Table } from 'antd';
import { Button as ButtonPermission } from 'components/Permission';
import { operatorRender } from 'utils/renderer';
import { tableScrollWidth } from 'utils/utils';
import intl from 'cpaas-front/lib/utils/intl';

var DataTable = /*#__PURE__*/function (_Component) {
  _inherits(DataTable, _Component);

  var _super = _createSuper(DataTable);

  function DataTable() {
    _classCallCheck(this, DataTable);

    return _super.apply(this, arguments);
  }

  _createClass(DataTable, [{
    key: "getColumns",
    value: function getColumns() {
      var _this = this;

      return [{
        title: intl.get('ciam.subAccount.model.api.serviceName').d('服务名'),
        dataIndex: 'serviceName',
        width: 160
      }, {
        title: intl.get('ciam.subAccount.model.api.method').d('请求方式'),
        dataIndex: 'method',
        width: 160
      }, {
        title: intl.get('ciam.subAccount.model.api.path').d('请求路径'),
        width: 400,
        dataIndex: 'path'
      }, {
        title: intl.get('ciam.subAccount.model.api.description').d('请求描述'),
        dataIndex: 'description'
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        key: 'operator',
        width: 110,
        fixed: 'right',
        render: function render(_, record) {
          var _this$props = _this.props,
              onApiFieldPermissionMaintain = _this$props.onApiFieldPermissionMaintain,
              path = _this$props.path;
          var operators = [];
          operators.push({
            key: 'gotoDetail',
            ele: /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.permissionMaintain"),
                type: 'button',
                meaning: '接口字段权限配置-字段权限维护'
              }],
              onClick: function onClick() {
                onApiFieldPermissionMaintain(record);
              }
            }, intl.get('ciam.subAccount.view.button.permissionMaintain').d('字段权限维护')),
            len: 6,
            title: intl.get('ciam.subAccount.view.button.permissionMaintain').d('字段权限维护')
          });
          return operatorRender(operators);
        }
      }];
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          dataSource = _this$props2.dataSource,
          pagination = _this$props2.pagination,
          _this$props2$loading = _this$props2.loading,
          loading = _this$props2$loading === void 0 ? false : _this$props2$loading,
          onChange = _this$props2.onChange;
      var columns = this.getColumns();
      return /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: "id",
        dataSource: dataSource,
        pagination: pagination,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        onChange: onChange,
        loading: loading
      });
    }
  }]);

  return DataTable;
}(Component);

export { DataTable as default };